package net.golfklubi.sive;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;


public class Jetty {
    private static boolean isStarted = false;
    private static Server server;

    public static void main(final String[] args) throws Exception {
        startApplication();
    }

    public static void startApplication() {
        server = new Server();
        final SocketConnector connector = new SocketConnector();
        connector.setMaxIdleTime(1000 * 60 * 60);
        connector.setSoLingerTime(-1);
        connector.setPort(8443);
        server.setConnectors(new Connector[] { connector });
        final WebAppContext bb = new WebAppContext();
        bb.setServer(server);
        bb.setContextPath("/sive");
        bb.setWar("src/main/webapp");

        server.addHandler(bb);
        try {
            server.start();
            isStarted = true;
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(100);
        }
    }

    public static void shutdownApplication() throws Exception {
        server.stop();
        server.join();
        isStarted = false;
    }

    public static boolean running() {
        return isStarted;
    }
}
